import { useState, useEffect } from "react";
import "./login.css";
import { useNavigate } from "react-router-dom";
import mmd from "../../assets/logo.jpg";
import { getLogin } from "../../tools/ajax";
function Login() {
  const navigate = useNavigate();
  const [user, setuser] = useState("");
  const [pasd, setpasd] = useState("");
  
  async function add() {
    console.log(user, pasd);
    const res = await getLogin({
      userName: user,
      password: pasd,
    });
    console.log(res);
    if (res.data.code == 1) {
      localStorage.setItem("token", res.data.token);
      navigate("/home");
    } else {
      alert("用户名或密码错误");
    }
  }
  useEffect(() => {}, []);
  return (
    <div className="log">
      <div className="content">
        <img src={mmd} alt="" />
        <h2 className="title">中国移动边缘UPF设备配置及报价系统</h2>
        <input
          type="text"
          placeholder="用户名"
          //   className="layui-input userName"
          value={user}
          onChange={(e) => {
            setuser(e.target.value);
          }}
        />
        <input
          name="password"
          type="password"
          placeholder="密码"
          //   className="layui-input password"
          value={pasd}
          onChange={(e) => {
            setpasd(e.target.value);
          }}
        />
        <button className="login-btn layui-btn layui-btn-normal" onClick={add}>
          登录
        </button>
      </div>
    </div>
  );
}
export default Login;
